﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using WorkFlowServiceTest;

public partial class BasePages_Agency : System.Web.UI.Page
{
    string UserId = "";
    WorkFlowService workflow = new WorkFlowService();

    protected void Page_Load(object sender, EventArgs e)
    {
        UserId = this.Page.User.Identity.Name;
        if (!IsPostBack)
        {
            Init(UserId);
        }

    }
    public void Init(string UserId)
    {
        txtAgencyUser.Text = UserId;
        DataTable dt = workflow.GetUserAgency(UserId);
        DataTable dts = workflow.GetDeptAgency(UserId);
        if (dts.Rows.Count > 0)
        {
            DataRow[] rows = dts.Select();
            //dt = dts.Clone();
            foreach (DataRow row in rows)
            {
                dt.ImportRow(row);
            } 
        }
       
        ddlworkflow.DataSource = dt;
        ddlworkflow.DataTextField = "FlowCaption";
        ddlworkflow.DataValueField = "WorkFlowId";
        ddlworkflow.DataBind();
    }
    protected void butConfirm_Click(object sender, EventArgs e)
    {
        WorkFlowServiceTest.WorkAgencyEntity agency = new WorkAgencyEntity();
        agency.AgencyId = Guid.NewGuid().ToString();
        agency.AgencyFormUser = txtAgencyUser.Text;
        agency.AgencyToUser = txtToUser.Text;
        agency.AgencyStartTime = txtstartTime.Text;
        agency.AgencyEndTime = txtendTime.Text;
        agency.Description = "1";
        workflow.Insert(agency);
    }
}